﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;

using Lidgren.Library.Network;
using System.Threading;
using System.Drawing;
using BBCommon;
using System.Runtime.InteropServices;
using Business;

namespace Client
{
   public static class Program
   {
      #region Properties

      [DllImport("user32.dll")]
      static extern bool FlashWindow(IntPtr hwnd, bool bInvert);

      private static System.Windows.Forms.NotifyIcon notifyIconNA;

      /// <summary>
      /// Obtient ou définit le LOG
      /// </summary>
      private static NetLog Log
      {
         get
         {
            return Program.ChatApplicationBusiness.Log;
         }
         set
         {
            Program.ChatApplicationBusiness.Log = value;
         }
      }
      private static NetAppConfiguration Config { get { return Program.ChatApplicationBusiness.Config; } }

      public static ChatForm MainForm;
      private static ChatApplication _chatApplicationBusiness;
      /// <summary>
      /// Permet d'utiliser l'application de CHAT
      /// </summary>
      private static ChatApplication ChatApplicationBusiness
      {
         get
         {
            if (Program._chatApplicationBusiness == null)
            {
               Program._chatApplicationBusiness = new ChatApplication();
               Program._chatApplicationBusiness.SendingMessage += new ChatApplication.SendingMessageEvent(_chatApplicationBusiness_SendingMessage);
               Program._chatApplicationBusiness.SendingSystemMessage += new ChatApplication.SystemMessage(_chatApplicationBusiness_SendingSystemMessage);
               Program._chatApplicationBusiness.UserCoffee += new EventHandler(_chatApplicationBusiness_UserCoffee);
               Program._chatApplicationBusiness.UserConnection += new ChatApplication.UserConnectionEvent(_chatApplicationBusiness_UserConnection);
               Program._chatApplicationBusiness.UserDisconnection += new ChatApplication.UserDisconnectionEvent(_chatApplicationBusiness_UserDisconnection);
               Program._chatApplicationBusiness.UserEat += new EventHandler(_chatApplicationBusiness_UserEat);
               Program._chatApplicationBusiness.UserKnocked += new EventHandler(_chatApplicationBusiness_UserKnocked);
               Program._chatApplicationBusiness.UserTyping += new ChatApplication.TypingInformation(_chatApplicationBusiness_UserTyping);
               Program._chatApplicationBusiness.NotifyMessage += new EventHandler(_chatApplicationBusiness_NotifyMessage);
               Program._chatApplicationBusiness.BASHActivated += new EventHandler(_chatApplicationBusiness_BASHActivated);
               Program._chatApplicationBusiness.VDMActivated += new EventHandler(_chatApplicationBusiness_VDMActivated);
            }

            return Program._chatApplicationBusiness;
         }
      }      

      public static Configuration AppConfig;
      /// <summary>
      /// Obtient ou définit le client
      /// </summary>
      public static NetClient Client
      {
         get
         {
            return Program.ChatApplicationBusiness.Client;
         }
         set
         {
            Program.ChatApplicationBusiness.Client = value;
         }
      }

      public static event EventHandler HiddenStateChanged;
      private static bool _currently_hidden;
      public static bool IsAppHidden
      {
         get { return _currently_hidden; }
         set
         {
            _currently_hidden = value;
            HiddenStateChanged(null, null);
         }
      }
      /// <summary>
      /// Obtient/Définit la liste des utilisateurs
      /// </summary>
      private static PlayerList PList
      {
         get
         {
            return Program.ChatApplicationBusiness.PList;
         }
         set
         {
            Program.ChatApplicationBusiness.PList = value;
         }
      }

      #endregion

      #region Methods


      internal static void Knock(string str, BBConversation conversation)
      {
         Program.ChatApplicationBusiness.Knock(str, conversation);
      }

      internal static void Coffee(string str, BBConversation conversation)
      {
         Program.ChatApplicationBusiness.Coffee(str, conversation);
      }

      internal static void Eat(string str, BBConversation conversation)
      {
         Program.ChatApplicationBusiness.Eat(str, conversation);
      }

      internal static BBConversation StartPrivateConversation(List<string> str)
      {
         return Program.ChatApplicationBusiness.StartPrivateConversation(str);
      }

      internal static void JoinConversation(BBConversation conversation, string player)
      {
         Program.ChatApplicationBusiness.JoinConversation(conversation, player);
      }

      internal static void LeaveConversation(BBConversation BBConversation, string p)
      {
         Program.ChatApplicationBusiness.LeaveConversation(BBConversation, p);
      }

      internal static void Shoot(string str)
      {
         Program.ChatApplicationBusiness.Shoot(str);
      }

      internal static void PrivateMessage(BBConversation bBConversation, string p, string p_3)
      {
         Program.ChatApplicationBusiness.PrivateMessage(bBConversation, p, p_3);
      }

      internal static void Entered(string p)
      {
         Program.ChatApplicationBusiness.Entered(p);
      }

      internal static void ShootResponse(ShootResponseDesc.Response response, string p)
      {
         Program.ChatApplicationBusiness.ShootResponse(response, p);
      }

      //<summary>
      /// The main entry point for the application.
      /// </summary>
      [STAThread]
      static void Main()
      {
         Application.EnableVisualStyles();
         Application.SetCompatibleTextRenderingDefault(false);
         //PList = new PlayerList();
         MainForm = new ChatForm();
         AppConfig = new Configuration();
         IsAppHidden = AppConfig.RunMinimized;

         // Create a configuration for the client
         Program.ChatApplicationBusiness.Config = new NetAppConfiguration("BBTcpTest");

         // enable encryption; this key was generated using the 'GenerateEncryptionKeys' application
         Config.EnableEncryption(
              "AQABwV1rQ1NDWzkkhUsYtMiRGjyxSn/zI13tros2RlXHlW6PA7Cvw2nOyMhDmweM+" +
              "T/+FWzssAWLh8qd+YHaMCCFskVdaZfRzquZlNOs9mX/vtxkLrXgBUaJQD/XOuBeJF" +
              "o3RfAKA4uhrEr7Bk1iB3zJQW1bSHK7KmmEWzMErk6iA7c=", null);

         Log = new NetLog();
         Log.IgnoreTypes = NetLogEntryTypes.Verbose; //  Verbose;
         Log.IsOutputToFileEnabled = false;

         Log.OutputFileName = "clientlog.html";

         // uncomment this if you want to start multiple instances of this process on the same computer
         //Log.OutputFileName = "clientlog" + System.Diagnostics.Process.GetCurrentProcess().Id + ".html";

         //Log.LogEvent += new EventHandler<NetLogEventArgs>(Log_LogEvent);

         Client = new NetClient(Config, Log);
         Client.StatusChanged += new EventHandler<NetStatusEventArgs>(Client_StatusChanged);

         Application.Idle += new EventHandler(ApplicationLoop);
         MainForm.TypingStateChanged += new EventHandler<ChatForm.TypingEvent>(MainForm_TypingStateChanged);

         CreateNotificationIcon();
         Application.Run(MainForm);

         if (Client != null)
            Client.Shutdown("Application exiting");

         if (notifyIconNA != null)
            notifyIconNA.Visible = false;
      }

      #endregion

      #region Events

      static void Client_StatusChanged(object sender, NetStatusEventArgs e)
      {
         Log.Info(e.Connection + ": " + e.Connection.Status + " - " + e.Reason);

         // If just connected, begin login procedure
         if (e.Connection.Status == NetConnectionStatus.Connected)
         {            
            Program.ChatApplicationBusiness.AskLogin(MainForm.Player, BBMessage.Version);            
         }
         // If connection drops, inform user and get back to the login form
         else if (e.Connection.Status == NetConnectionStatus.Disconnected)
         {
            try // The following fails if application is exiting
            {
               PList = new PlayerList();
               Program.ChatApplicationBusiness.OutputSystemText("Disconnected ! Reason : " + e.Reason, null);
               MainForm.Connect();
            }
            catch { }
         }

      }

      static void ApplicationLoop(object sender, EventArgs e)
      {         
         while (Win32.AppStillIdle)
         {
            if (Client != null)
            {
               // call heartbeat as often as possible; this sends queued packets,
               // keepalives and acknowledges etc.
               Client.Heartbeat();

               NetMessage msg;
               // read a packet if available
               while ((msg = Client.ReadMessage()) != null)
                  Program.ChatApplicationBusiness.HandleMessage(msg);

               Thread.Sleep(1); // don't hog the cpu
            }
         }
      }

      static void MainForm_TypingStateChanged(object sender, ChatForm.TypingEvent e)
      {
         BBConversation convers = sender as BBConversation;
         // Create istyping message
         BBMessage msg = new BBMessage();
         msg.MsgTypingMsg(e.isTyping);
         msg.Conversation = convers;

         // Send it.
         Client.SendMessage(msg.GetNetMessage(), NetChannel.ReliableUnordered);
      }

      static void CreateNotificationIcon()
      {
         // Initialize Notification Area Icon
         notifyIconNA = new System.Windows.Forms.NotifyIcon();
         notifyIconNA.Icon = MainForm.Icon;
         notifyIconNA.Text = "BB Communicator";

         notifyIconNA.Visible = true;
         notifyIconNA.MouseClick += new System.Windows.Forms.MouseEventHandler(NA_MouseClick);

         MainForm.SizeChanged += new EventHandler(MainForm_SizeChanged);
      }

      static void NA_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
      {
         if (e.Button == System.Windows.Forms.MouseButtons.Left)
         {
            IsAppHidden = false;
         }
      }

      static void MainForm_SizeChanged(object sender, EventArgs e)
      {
         notifyIconNA.Icon = MainForm.Icon;
      }

      #endregion

      #region Tools

      static void ShowInfoBalloon(string title, string content, System.Windows.Forms.ToolTipIcon icon)
      {
         if (!MainForm.ContainsFocus)
            notifyIconNA.ShowBalloonTip(500, title, content, icon);
         NotifyMessage();
      }

      public static void NotifyMessage()
      {
         if (!MainForm.ContainsFocus)
         {
            FlashWindow(MainForm.Handle, true);
         }
         if (MainForm.Visible == false)
            notifyIconNA.Icon = Resource1.Mail;
      }

      #endregion

      #region Handlers

      static void _chatApplicationBusiness_UserTyping(PlayerCarac playerCarac, BBConversation conversation, bool isTyping)
      {
         if (conversation == null)
            MainForm.UserIsTypingMsg(playerCarac.Nick, isTyping);
         else
            MainForm.UserIsTypingMsg(playerCarac.Nick, isTyping, conversation);
      }

      static void _chatApplicationBusiness_UserKnocked(object sender, EventArgs e)
      {
         Program.ShowInfoBalloon("Alert Message", "Knock Knock", ToolTipIcon.Info);
      }

      static void _chatApplicationBusiness_UserEat(object sender, EventArgs e)
      {
         Program.ShowInfoBalloon("Go to eat...", "Let's go eat something", ToolTipIcon.Info);
      }

      static void _chatApplicationBusiness_UserDisconnection(PlayerCarac playerCarac, string reason)
      {
         MainForm.UserDisconnect(playerCarac.Nick, reason);
      }

      static void _chatApplicationBusiness_UserConnection(PlayerCarac playerCarac, bool newPlayer)
      {
         MainForm.UserConnect(playerCarac.Nick, newPlayer);
      }

      static void _chatApplicationBusiness_UserCoffee(object sender, EventArgs e)
      {
         Program.ShowInfoBalloon("Breaking work", "Let's go have some fun... Coffee ?", ToolTipIcon.Info);
      }

      static void _chatApplicationBusiness_SendingSystemMessage(string message, BBMessage BBmessage)
      {
         if (BBmessage != null)
         {
            if (BBmessage.Conversation == null)
               MainForm.AppendSysMsg(message);
            else
               MainForm.AppendSysMsgBBMessage(BBmessage, message, true);
         }
      }

      static void _chatApplicationBusiness_SendingMessage(BBMessage message)
      {
         if (message.Conversation == null)
            MainForm.AppendChatMsg(message.Message, message.PlayerCarac.Nick, message.PlayerCarac.TextColor);
         else
            MainForm.AppendChatMsgBBMessage(message, message.Message, message.PlayerCarac.Nick, message.PlayerCarac.TextColor, message.Conversation.ToString());
      }

      static void _chatApplicationBusiness_NotifyMessage(object sender, EventArgs e)
      {
         if (!MainForm.ContainsFocus)
         {
            FlashWindow(MainForm.Handle, true);
         }
         if (MainForm.Visible == false)
            notifyIconNA.Icon = Resource1.Mail;
      }

      static void _chatApplicationBusiness_VDMActivated(object sender, EventArgs e)
      {
         Program.ShowInfoBalloon("VDM news !", "Eyh ! Here we are some VDM", ToolTipIcon.Info);
      }

      static void _chatApplicationBusiness_BASHActivated(object sender, EventArgs e)
      {
         Program.ShowInfoBalloon("Bash-Fr !", "Eyh ! Some people are really crazy", ToolTipIcon.Info);
      }

      #endregion
   }


   //public static class ProgramToto
   //{
   //    private static System.Windows.Forms.NotifyIcon notifyIconNA;

   //    public static ChatForm MainForm;
   //    public static NetClient Client;
   //    public static NetLog Log;
   //    public static NetAppConfiguration Config;

   //    private static bool _currently_hidden;
   //    public static event EventHandler HiddenStateChanged;
   //    public static bool IsAppHidden
   //    {
   //        get { return _currently_hidden; }
   //        set
   //        {
   //            _currently_hidden = value;
   //            HiddenStateChanged(null, null);
   //        }
   //    }


   //    public static Configuration AppConfig;

   //    public static PlayerList PList;
   //    public static int OurID;

   //    [DllImport("user32.dll")]
   //    static extern bool FlashWindow(IntPtr hwnd, bool bInvert);

   //    /// <summary>
   //    /// The main entry point for the application.
   //    /// </summary>
   //    [STAThread]
   //    static void Main()
   //    {
   //        Application.EnableVisualStyles();
   //        Application.SetCompatibleTextRenderingDefault(false);
   //        PList = new PlayerList();
   //        MainForm = new ChatForm();
   //        AppConfig = new Configuration();
   //        IsAppHidden = AppConfig.RunMinimized;

   //        // Create a configuration for the client
   //        Config = new NetAppConfiguration("BBTcpTest");

   //        // enable encryption; this key was generated using the 'GenerateEncryptionKeys' application
   //        Config.EnableEncryption(
   //             "AQABwV1rQ1NDWzkkhUsYtMiRGjyxSn/zI13tros2RlXHlW6PA7Cvw2nOyMhDmweM+" +
   //             "T/+FWzssAWLh8qd+YHaMCCFskVdaZfRzquZlNOs9mX/vtxkLrXgBUaJQD/XOuBeJF" +
   //             "o3RfAKA4uhrEr7Bk1iB3zJQW1bSHK7KmmEWzMErk6iA7c=", null);

   //        Log = new NetLog();
   //        Log.IgnoreTypes = NetLogEntryTypes.Verbose; //  Verbose;
   //        Log.IsOutputToFileEnabled = false;

   //        Log.OutputFileName = "clientlog.html";

   //        // uncomment this if you want to start multiple instances of this process on the same computer
   //        //Log.OutputFileName = "clientlog" + System.Diagnostics.Process.GetCurrentProcess().Id + ".html";

   //        //Log.LogEvent += new EventHandler<NetLogEventArgs>(Log_LogEvent);

   //        Client = new NetClient(Config, Log);
   //        Client.StatusChanged += new EventHandler<NetStatusEventArgs>(Client_StatusChanged);

   //        Application.Idle += new EventHandler(ApplicationLoop);
   //        MainForm.TypingStateChanged += new EventHandler<ChatForm.TypingEvent>(MainForm_TypingStateChanged);

   //        CreateNotificationIcon();
   //        Application.Run(MainForm);

   //        if (Client != null)
   //            Client.Shutdown("Application exiting");

   //        if (notifyIconNA != null)
   //            notifyIconNA.Visible = false;
   //    }

   //    static void MainForm_TypingStateChanged(object sender, ChatForm.TypingEvent e)
   //    {
   //       BBConversation convers = sender as BBConversation;
   //       // Create istyping message
   //       BBMessage msg = new BBMessage();
   //       msg.MsgTypingMsg(e.isTyping);
   //       msg.Conversation = convers;

   //       // Send it.
   //       Client.SendMessage(msg.GetNetMessage(), NetChannel.ReliableUnordered);
   //    }

   //    public static PlayerCarac CreatePlayerCarac(PlayerClass playerclass)
   //    {
   //       PlayerCarac Player = new PlayerCarac();
   //       Player.Nick = Program.AppConfig.Nick;
   //       Player.Type = playerclass;
   //       Player.TextColor = Program.AppConfig.TextColor;

   //       return Player;
   //    }

   //    static void ApplicationLoop(object sender, EventArgs e)
   //    {
   //        while (Win32.AppStillIdle)
   //        {
   //            if (Client != null)
   //            {
   //                // call heartbeat as often as possible; this sends queued packets,
   //                // keepalives and acknowledges etc.
   //                Client.Heartbeat();

   //                NetMessage msg;
   //                // read a packet if available
   //                while ((msg = Client.ReadMessage()) != null)
   //                    Program.ChatApplicationBusiness.HandleMessage(msg);

   //                Thread.Sleep(1); // don't hog the cpu
   //            }
   //        }
   //    }        

   //    private static bool isPartOfConversation(BBConversation conversation)
   //    {
   //        if (conversation != null)
   //        {
   //            foreach (string play in conversation.Players)
   //            {
   //               if (PList.GetPlayer(play) != null)
   //               {
   //                if (OurID == PList.GetPlayer(play).Carac.ActorID)
   //                    return true;
   //                  }
   //            }
   //        }

   //        return false;
   //    }

   //    private static void ShootResponsed(BBMessage msg)
   //    {
   //        string dest = PList.GetPlayer(msg.ActorInfo.Id).Carac.Nick;
   //        string src = PList.GetPlayer(msg.Resp.SenderID).Carac.Nick;

   //        switch (msg.Resp.ShootResponse)
   //        {
   //            case ShootResponseDesc.Response.AVOIDED:
   //                OutputSystemText(dest + " avoided " + src + "'s snowball! He's too fast, is he really working ?");
   //                break;

   //            case ShootResponseDesc.Response.COUNTERED:
   //                OutputSystemText(dest + " countered " + src + "'s snowball! Seems like he's working but still got some nerves");
   //                break;

   //            case ShootResponseDesc.Response.TAKEN:
   //                OutputSystemText(dest + " couldn't handle " + src + "'s snowball... What a loser.");
   //                break;

   //            case ShootResponseDesc.Response.TOO_MUCH:
   //                OutputSystemText(dest + " is already dealing with a snowball, " + src + " should calm down a bit.");
   //                break;
   //        }
   //    }

   //    private static void Shooted(BBMessage msg)
   //    {
   //        if (msg.Shoot.Cible_ID == OurID)
   //        {
   //            // We are the destination
   //            if (msg.ActorInfo.Id == OurID)
   //            {
   //                // Are you dumb ?
   //                OutputSystemText("You crush your snowball on your head. You feel cold, and somehow alone.");
   //            }
   //            else
   //            {
   //                MainForm.ShootSnowBall(PList.GetPlayer(msg.ActorInfo.Id).Carac.Nick);
   //            }
   //        }
   //        else
   //        {
   //            if (msg.ActorInfo.Id == msg.Shoot.Cible_ID)
   //                OutputSystemText(PList.GetPlayer(msg.ActorInfo.Id).Carac.Nick + " crushed a snowball on his own head, and looks dumb.");
   //            else
   //                OutputSystemText(PList.GetPlayer(msg.ActorInfo.Id).Carac.Nick + " threw a snowball at " + PList.GetPlayer(msg.Shoot.Cible_ID).Carac.Nick + "'s head!");
   //        }
   //    }

   //    static void Log_LogEvent(object sender, NetLogEventArgs e)
   //    {
   //        OutputSystemText(e.Entry.What);
   //    }

   //    static void OutputSystemText(string str)
   //    {
   //        try
   //        {
   //            if (MainForm != null && !MainForm.Disposing && !MainForm.IsDisposed)
   //            {
   //                MainForm.AppendSysMsg(str);
   //            }
   //        }
   //        catch { } // ignore disposal problems
   //    }       

   //    static void Client_StatusChanged(object sender, NetStatusEventArgs e)
   //    {
   //        Log.Info(e.Connection + ": " + e.Connection.Status + " - " + e.Reason);

   //        // If just connected, begin login procedure
   //        if (e.Connection.Status == NetConnectionStatus.Connected)
   //        {
   //            // Create login message
   //            BBMessage msg = new BBMessage();
   //            msg.MsgAskLogin(MainForm.Player, BBMessage.Version);

   //            // Send it.
   //            Client.SendMessage(msg.GetNetMessage(), NetChannel.ReliableUnordered);
   //        }
   //        // If connection drops, inform user and get back to the login form
   //        else if (e.Connection.Status == NetConnectionStatus.Disconnected)
   //        {
   //            try // The following fails if application is exiting
   //            {
   //                PList = new PlayerList();
   //                OutputSystemText("Disconnected ! Reason : " + e.Reason);
   //                MainForm.Connect();
   //            }
   //            catch { }
   //        }

   //    }

   //    internal static void Entered(string cmd)
   //    {
   //        if (Client != null)
   //        {
   //            if (Client.Status == NetConnectionStatus.Connected)
   //            {
   //                // Create a message
   //                BBMessage msg = new BBMessage();
   //                msg.MsgChat(cmd);

   //                // Send use the ReliableUnordered channel; ie. it WILL arrive, but not necessarily in order
   //                Client.SendMessage(msg.GetNetMessage(), NetChannel.ReliableUnordered);
   //            }
   //        }
   //    }

   //    #region Notification Area

   //    static void CreateNotificationIcon()
   //    {
   //        // Initialize Notification Area Icon
   //        notifyIconNA = new System.Windows.Forms.NotifyIcon();
   //        notifyIconNA.Icon = MainForm.Icon;
   //        notifyIconNA.Text = "BB Communicator";

   //        notifyIconNA.Visible = true;
   //        notifyIconNA.MouseClick += new System.Windows.Forms.MouseEventHandler(NA_MouseClick);

   //        MainForm.SizeChanged += new EventHandler(MainForm_SizeChanged);
   //    }

   //    static void MainForm_SizeChanged(object sender, EventArgs e)
   //    {
   //        notifyIconNA.Icon = MainForm.Icon;
   //    }

   //    static void NA_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
   //    {
   //        if (e.Button == System.Windows.Forms.MouseButtons.Left)
   //        {
   //            IsAppHidden = false;
   //        }
   //    }

   //    public static void NotifyMessage()
   //    {
   //        if (!MainForm.ContainsFocus)
   //        {
   //            FlashWindow(MainForm.Handle, true);
   //        }
   //        if (MainForm.Visible == false)
   //            notifyIconNA.Icon = Resource1.Mail;
   //    }

   //    #endregion

   //    internal static void Shoot(string nick)
   //    {
   //        // Create a message
   //        BBMessage msg = new BBMessage();
   //        msg.MsgActorShoot(new ShootDescription(ShootDescription.Type.SNOWBALL, PList.GetPlayer(nick).Carac.ActorID));

   //        // Send use the ReliableUnordered channel; ie. it WILL arrive, but not necessarily in order
   //        Client.SendMessage(msg.GetNetMessage(), NetChannel.ReliableUnordered);
   //    }

   //    internal static void ShootResponse(ShootResponseDesc.Response response, string nick)
   //    {
   //        // Create a message
   //        int id = PList.GetPlayer(nick).Carac.ActorID;
   //        BBMessage msg = new BBMessage();
   //        msg.MsgShootResponse(new ShootResponseDesc(response, id));

   //        // Send use the ReliableUnordered channel; ie. it WILL arrive, but not necessarily in order
   //        Client.SendMessage(msg.GetNetMessage(), NetChannel.ReliableUnordered);
   //    }

   //    internal static void Knock(string nick)
   //    {
   //        // Create a message
   //        BBMessage msg = new BBMessage();
   //        msg.MsgKnock("", PList.GetPlayer(nick).Carac.ActorID);

   //        // Send use the ReliableUnordered channel; ie. it WILL arrive, but not necessarily in order
   //        Client.SendMessage(msg.GetNetMessage(), NetChannel.ReliableUnordered);
   //    }

   //    internal static void Coffee(string nick)
   //    {
   //        // Create a message
   //        BBMessage msg = new BBMessage();
   //        msg.MsgCoffee("", PList.GetPlayer(nick).Carac.ActorID);

   //        // Send use the ReliableUnordered channel; ie. it WILL arrive, but not necessarily in order
   //        Client.SendMessage(msg.GetNetMessage(), NetChannel.ReliableUnordered);
   //    }

   //    internal static void Eat(string nick)
   //    {
   //        // Create a message
   //        BBMessage msg = new BBMessage();
   //        msg.MsgEat("", PList.GetPlayer(nick).Carac.ActorID);

   //        // Send use the ReliableUnordered channel; ie. it WILL arrive, but not necessarily in order
   //        Client.SendMessage(msg.GetNetMessage(), NetChannel.ReliableUnordered);
   //    }

   //    internal static void PrivateMessage(BBConversation convers, string text, string actualnick)
   //    {
   //        if (convers != null)
   //        {
   //            // Create a message
   //            BBMessage msg = new BBMessage();
   //            msg.Conversation = convers;

   //            msg.MsgPrivateMessage(text, actualnick);

   //            // Send use the ReliableUnordered channel; ie. it WILL arrive, but not necessarily in order
   //            Client.SendMessage(msg.GetNetMessage(), NetChannel.ReliableUnordered);
   //        }
   //    }

   //    internal static void LeaveConversation(BBConversation convers, string actualnick)
   //    {
   //        if (convers != null)
   //        {
   //           if (convers.Players.Contains(actualnick))
   //           {
   //              convers.Players.Remove(actualnick);

   //              BBMessage msg = new BBMessage();
   //              msg.Conversation = convers;

   //              msg.MsgLeaveConversationPlayer(PList.GetPlayer(actualnick).Carac.ActorID, string.Empty);

   //              Client.SendMessage(msg.GetNetMessage(), NetChannel.ReliableUnordered);
   //           }
   //        }
   //    }

   //    internal static void JoinConversation(BBConversation convers, string actualnick)
   //    {
   //        if (convers != null)
   //        {
   //            BBMessage msg = new BBMessage();
   //            msg.Conversation = convers;

   //            msg.MsgJoinConversationPlayer(PList.GetPlayer(actualnick), true);

   //            Client.SendMessage(msg.GetNetMessage(), NetChannel.ReliableUnordered);
   //        }
   //    }

   //    internal static BBConversation StartPrivateConversation(List<string> users)
   //    {
   //       return Program.ChatApplicationBusiness.StartPrivateConversation(users);
   //    }

   //    internal static void PrivateConversation(string nick, string text)
   //    {
   //       Program.ChatApplicationBusiness.PrivateConversation(nick, text);
   //    }

   //    internal static void ShowInfoBalloon(string content)
   //    {
   //        if (!MainForm.ContainsFocus)
   //            notifyIconNA.ShowBalloonTip(500, "Attention request", content, System.Windows.Forms.ToolTipIcon.Info);
   //        NotifyMessage();
   //    }

   //    static void ShowInfoBalloon(string title, string content)
   //    {
   //        if (!MainForm.ContainsFocus)
   //            notifyIconNA.ShowBalloonTip(500, title, content, System.Windows.Forms.ToolTipIcon.Info);
   //        NotifyMessage();
   //    }

   //    static void ShowInfoBalloon(string title, string content, System.Windows.Forms.ToolTipIcon icon)
   //    {
   //        if (!MainForm.ContainsFocus)
   //            notifyIconNA.ShowBalloonTip(500, title, content, icon);
   //        NotifyMessage();
   //    }
   //}
}
